package com.wer.controller;

import com.wer.entity.Flower;
import com.wer.service.FlowerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 黄军艳
 * @version 1.0
 * @date 2024/12/18  8:43
 */
@Controller
public class FlowerController {
    Logger logger= LoggerFactory.getLogger(FlowerController.class);

    @Autowired
    private FlowerService flowerService;

    @RequestMapping("/list")
    public String list(Model model){
        List<Flower> flowerList=new ArrayList<>();
        flowerList=flowerService.selectAll();
        model.addAttribute("flowerList",flowerList);
        return "list";
    }

    @RequestMapping("/add")
    public String add(){
        return "add";
    }

    @RequestMapping("/save")
    public String save(Flower flower){
        int count=flowerService.insert(flower);
        if(count>0){
            return "redirect:/list";
        }
        return "redirect:/list";
    }

    @RequestMapping("/detail")
    public String detail(@RequestParam("id") int id, Model model){
        Flower flower=flowerService.detail(id);
        model.addAttribute("flower",flower);
        return "detail";
    }
}
